﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Data.NHibernate.Generic.Support;
using GoodsInvoicing.DAL.DAO.UserRole;
using GoodsInvoicing.Model.UserRole;
using NHibernate;
using NHibernate.Impl;

namespace GoodsInvoicing.DAL.Hibernate.UserRole
{
    public class GI_UserDAOHibernate : BaseHibernate<GI_User, int>, GI_UserDAO
    {
        public GI_User Get(string loginName, string loginPWD)
        {
            IList<GI_User> userList = HibernateTemplate.Find<GI_User>("from GI_User u where u.LoginName = ? and u.LoginPWD = ?", new Object[] { loginName, loginPWD });
            if (userList.Count == 0)
            {
                return null;
            }
            else 
            {
                return userList[0];
            }
        }


        public IList<GI_User> Search(GI_User user)
        {
            //ICriteria criteria = Session.CreateCriteria<GI_User>();
            //return criteria.List<GI_User>();
        
            string sql = "from GI_User u where 1=1 ";
            if (user.UserName != "" && !user.UserName.Equals(""))
            {
                sql += "and u.UserName like '%" + user.UserName + "%' ";
            }
            return HibernateTemplate.Find<GI_User>(sql);
        }
    }
}
